import * as chalk from 'chalk';
import * as express from 'express';
import { Request, Response } from "express";
import routers from './router';

const app = express();
const port = 3001;

app.use( (req: Request, res: Response, next: Function) => {
  console.log(`request from ip ${req.ip} for ${req.url}`);
  next();
});

app.get('/', (req: Request, res: Response) => {
  res.send('Hello World!');
});

routers.forEach((router, index) => {
  app.use(router.path, router.application);
});


app.listen(port, () => {
  console.log(`mock server listening ${chalk.blue('http://localhost:')}${chalk.blue(port)}`);
});

